package org.darcy.admin.task.product;

import org.darcy.common.utils.DateUtil;
import org.darcy.service.service.StoreBargainService;
import org.darcy.service.service.StoreCombinationService;
import org.darcy.service.service.StoreProductService;
import org.darcy.service.service.StoreSeckillService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 操作商品库存
 */
@Component
@Configuration
@EnableScheduling
public class ProductStockTask {
	// 日志
	private static final Logger logger = LoggerFactory.getLogger(ProductStockTask.class);

	@Autowired
	private StoreProductService storeProductService;

	@Autowired
	private StoreSeckillService storeSeckillService;

	@Autowired
	private StoreBargainService storeBargainService;

	@Autowired
	private StoreCombinationService storeCombinationService;

	@Scheduled(fixedDelay = 1000 * 60L) // 1分钟同步一次数据
	public void init() {
		logger.info("操作商品库存: {}", DateUtil.nowDateTimeStr());
		try {
			storeProductService.consumeProductStock(); // 商品本身库存任务
			storeSeckillService.consumeProductStock(); // 秒杀本身库存任务
			storeBargainService.consumeProductStock(); // 砍价本身库存任务
			storeCombinationService.consumeProductStock(); // 拼团本身库存任务
		} catch (Exception e) {
			logger.error("OrderTakeByUser.task" + " | msg : " + e.getMessage());
		}

	}
}
